package com.thinkit.bigdata.core.util;

import com.thinkit.bigdata.core.ConfigHelper;
import com.thinkit.bigdata.web.coremet.SystemStatic;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class ProjectPubMet {

    /**
     * 按照省份登陆ftp
     * @return -
     */
    public FtpUtil getFtpUtilByArea(String provinceCode) {
        String host = ConfigHelper.getString("ftp.host");
        String port = ConfigHelper.getString("ftp.port");
        String username = ConfigHelper.getString("ftp.username");
        String password = ConfigHelper.getString("ftp.password");
        Map<String, Map<String, String>> maps = SystemStatic.FTP_CONFIG_MAP;
        Map<String, String> mes = maps.get(provinceCode);
        if (mes != null) {
            host = mes.get("host");
            port = mes.get("port");
            username = mes.get("username");
            password = mes.get("password");
        }
        return new FtpUtil(
                host,
                Integer.parseInt(port),
                DESUtils.getDecryptString(username),
                DESUtils.getDecryptString(password)
        );
    }
    /**
     * 登陆ftp
     * @return -
     */
    public FtpUtil getFtpUtil() {
        return new FtpUtil(
                ConfigHelper.getString("ftp.host"),
                Integer.parseInt(ConfigHelper.getString("ftp.port")),
                DESUtils.getDecryptString(ConfigHelper.getString("ftp.username")),
                DESUtils.getDecryptString(ConfigHelper.getString("ftp.password"))
        );
    }
}
